package com.xncoding.freemarker.handler;

import com.xncoding.starter.inter.Reading;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Slf4j
@Service
public class ReadingHandler {

    /**
     * 因为若application.yml中没有reading相关配置,starter中自动装配不会生效，
     * 默认的Reading实现不会被初始化，会导致在SpringBoot启动时抛异常。
     * 所以这里required设置为false，表示ReadingHandler初始化时，不强制要求一定要注入Reading实现
     */
    @Autowired(required = false)
    private Reading reading;

    @PostConstruct
    public void init() {
        // 若当前Reading实现不为空，调用其reading()方法，否则打印reading is null...
        if (this.reading != null) {
            this.reading.reading();
        } else {
            System.out.println("reading is null...");
        }
    }

}
